﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CP.Entities;
using CP.Win.IViews.GPM;
using CP.Repositories.GPM;
using CP.Utility;
using System.Data;

namespace CP.Controllers.GPM
{
    public class ButtonAuthorizeController
    {
        public IButtonAuthorizeView View { get; private set; }
        public ButtonAuthorizeRepsitory Repository { get; private set; }

        public ButtonAuthorizeController(IButtonAuthorizeView view)
        {
            this.View = view;
            this.Repository = new ButtonAuthorizeRepsitory();

            this.View.AuthButton += new AuthButtonHandler(View_AuthButton);
            this.View.UnAuthButton += new UnAuthButtonHandler(View_UnAuthButton);
            this.View.EditValueChanged += new EditValueChangedHandler(View_EditValueChanged);  
        }

        void View_EditValueChanged(int groupid, int webpartid)
        {
            IList<Button_List> unAuthBtns = this.Repository.GetUnAuthBtns(groupid, webpartid);
            this.View.BindUnAuthBtns(unAuthBtns);
            IList<Button_List> authBtns = this.Repository.GetAuthBtns(groupid, webpartid);
            this.View.BindAuthBtns(authBtns);
        }

        void View_AuthButton(int groupid, int menuid, IList<int> btns)
        {
            this.Repository.ButtonAuth(groupid, menuid, btns);
        }

        void View_UnAuthButton(int groupid, int menuid, IList<int> btns)
        {
            this.Repository.ButtonUnAuth(groupid, menuid, btns);
        }

    }
}
